<template>
	<view class="index-box">
		<sww-nav-bar v-if="navInit" :borderBottom="false" :title="title" :background="bgColor || '#ffffff'" :titleColor="fColor || '#000000'"></sww-nav-bar>
		<home-page ref="modulePageRef" @changNav="changNav" @changTopic="changTopic"></home-page>
		<template v-for="(item,index) in pageIds">
			<home-page v-show="currentIndex === index" :key="index" :ref="'moduleOther_' + index" :pageId="item" :autoInit="false"></home-page>
		</template>
		<!-- <view class="technology_payment" v-if="vuex_business.technical_support?true:false">
			{{ vuex_business.technical_support }}
		</view> -->
		<sww-sidebar v-if="navInit" :scroll-top="scrollTop" :contact="contact" :hasTop="hasTop"></sww-sidebar>
		<u-popup mode="center" v-model="visible" contBg="transparent" :mask-close-able="false">
			<view>
				<image class="adver_img" :src="popupItem.img" mode="widthFix" @click="goLink"></image>
				<view v-if="popupItem.mini_url != 'closed'" @click="visible = false" class="cha iconfont iconfont-e725"></view>
			</view>
		</u-popup>
		<sww-login></sww-login>
	</view>
</template>
<script>
	import { pageShare } from '../../mixins/pageShare';
	import homePage from '@/pagecomponents/homePage/homePage';
	import {
		mapState
	} from 'vuex';
	import {
		pathLink
	} from '@/utils/jump.js';
	export default {
		mixins: [pageShare],
		props: {
			tabIndex: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				pageIds: [],
				currentIndex: 0,
				scrollTop: 0,
				bgColor: '',
				fColor: '',
				contact: false,
				hasTop: false,
				navInit: false,
				title: '',
				popupItem: {},
				visible: false
			};
		},
		components: {
			homePage
		},
		computed: {
			...mapState(['vuex_tab_bar'])
		},
		mounted() {
			let obj = this.vuex_tab_bar.list[this.tabIndex];
			this.title = obj.query.title || this.vuex_business.name;
			// let val = uni.getStorageSync('advertisement')
			this.$resPost('GetCommonPicList', {
				type: 13
			}).then(({
				data
			}) => {
				if (data[0] && data[0].img) {
					// if(!val || val != data[0].img){ // 第一次进来或者广告图有变化
					this.popupItem = data[0];
					this.visible = true;
					// uni.setStorageSync('advertisement', data[0].img)
					if(data[0].side_pic && data[0].side_pic != '0'){
						let time = Number(data[0].side_pic) || 5
						time = time * 1000
						setTimeout(() => {
							this.visible = false;
						}, time);
					}
					// }
				} else {
					// uni.removeStorage({
					//     key: 'advertisement'
					// })
				}
			});
		},
		methods: {
			changNav(item) {
				this.contact = item.contact
				this.hasTop = item.hasTop
				this.bgColor = item.bgColor;
				this.fColor = item.fColor
				this.navInit = true;
				let obj = {
					...this.vuex_config
				}
				obj.contact = item.contact
				this.$u.vuex('vuex_config', {
					...obj
				});
			},
			changTopic(obj) {
				if (obj.arrid) {
					this.pageIds = [].concat(obj.arrid)
				}
				this.currentIndex = obj.index
				this.$nextTick(() => {
					let str = 'moduleOther_' + obj.index
					if (this.$refs[str][0].manualInit) {
						this.$refs[str][0].manualInit();
					}
				})
			},
			$onLoad() {},
			$onShow() {
				this.shareOnshow();
			},
			$onHide() {},
			$onPullDownRefresh() {
				this.pageIds = []
				if (this.$refs.modulePageRef.$onPullDownRefresh) {
					this.$refs.modulePageRef.$onPullDownRefresh();
				}
			},
			$onReachBottom() {
				let str = 'moduleOther_' + this.currentIndex
				if (!this.pageIds[0] && this.$refs.modulePageRef.$onReachBottom) {
					this.$refs.modulePageRef.$onReachBottom();
				} else if (this.$refs[str][0] && this.$refs[str][0].$onReachBottom) {
					this.$refs[str][0].$onReachBottom();
				}
			},
			$onPageScroll(e) {
				this.scrollTop = e.scrollTop;
			},
			goLink() {
				if (this.popupItem.mini_url) {
					if(this.popupItem.mini_url == 'closed'){
						this.visible = false;
						return
					}
					if (this.popupItem.mini_url.includes('loginAuth')) {
						this.$login('goLink').then(() => {
							pathLink({
								path: this.popupItem.mini_url
							});
						});
					} else {
						pathLink({
							path: this.popupItem.mini_url
						});
					}
					this.visible = false;
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.technology_payment {
		width: 100%;
		padding: 20rpx 0;
		text-align: center;
		color: #999;
	}

	.adver_img {
		width: 525rpx;
	}

	.cha {
		color: #d6d3d3;
		font-size: 70rpx;
		margin-top: 50rpx;
	}
</style>
